/**   
 * @Title: DaletouChaseExceptCommunicater.java 
 * @Package com.esun.rabbit2.communicaters 
 * @Description: (大乐透获取追好期号列表接口) 
 * @author: Billy Qigs@500wan.com   
 * @date: 2011-11-22 上午11:47:22  
 * Copyright: (C) 2011 Shenzhen E-sun Sky Net Technology Co.,ltd.
 */
package com.esun.rabbit2.communicaters;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;

import javax.xml.parsers.ParserConfigurationException;

import org.apache.http.client.ClientProtocolException;
import org.xml.sax.SAXException;

import com.esun.config.BussinessCode;
import com.esun.config.Config;
import com.esun.config.Key;
import com.esun.model.UserInfo;
import com.esun.network.ServerCommunicater;

/**
 * @ClassName: DaletouChaseExceptCommunicater
 * @Description: (大乐透获取追好期号列表接口)
 * @author: Billy Qigs@500wan.com
 * @date: 2011-11-22 上午11:47:22
 * 
 */
public class DaletouTraceExpectCommunicater extends ServerCommunicater {

	private String msgServer;
	private StringBuffer expectList = new StringBuffer();

	public String getMsgServer() {
		return msgServer;
	}

	public void setMsgServer(String str) {
		this.msgServer = str;
	}

	public boolean isGetExpectSucceed(String startExpect, String num) throws ClientProtocolException, IOException, ParserConfigurationException, SAXException {
		boolean isSucceed = false;

		ArrayList<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>();
		list.add(mapItem(BussinessCode.PASER_MID, BussinessCode.MID_TRACK_EXCEPTION_DLT));
		list.add(mapItem(BussinessCode.PASER_CK, UserInfo.getUserInfo().getUserSession()));
		list.add(mapItem(Key.KEY_EXPECT, startExpect));
		list.add(mapItem(Key.KEY_NUM, num));

		super.getServerResponse(list, true);
		setMsgServer(super.getServerMsg());
		if (super.getState() == 100) {
			isSucceed = true;
			setTrackExceptionList(super.getListResult());
		}

		return isSucceed;
	}

	public String getTrackExceptionList() {
		return expectList.toString();
	}

	private void setTrackExceptionList(ArrayList<Hashtable<String, String>> list) {

		cleanList();

		for (int i = 0; i < list.size(); i++) {
			expectList.append(list.get(i).get(Key.KEY_EXPECT));
			if (i != list.size() - 1) {
				expectList.append(Config.COMMA);
			}
		}
	}

	private HashMap<String, String> mapItem(String name, String value) {
		HashMap<String, String> map = new HashMap<String, String>();
		map.put(name, value);
		return map;
	}

	/**
	 * @Title: cleanList
	 * @Description: 清除expectlist内容
	 * @param: 设定文件
	 * @return: void 返回类型
	 * @throws
	 */
	private void cleanList() {

		int size = expectList.length();
		if (size != 0) {
			expectList.delete(0, size);
		}

	}

}
